package com.bay1ts.service.impl;

import com.bay1ts.dao.*;
import com.bay1ts.domain.Request;
import com.bay1ts.service.TeacherService;
import com.bay1ts.utils.RequestStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenuu on 2016/4/2.
 */
@Service("teacherService")
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private UsersMapper usersMapper;
    @Autowired
    private RequestMapper requestMapper;
    @Autowired
    private SubjectContestMapper subjectContestMapper;
    @Autowired
    private VocationaQualificationMapper vocationaQualificationMapper;
    @Autowired
    private EntrepreneurshipMapper entrepreneurshipMapper;
    //这里应该是获得所有的 处于申请状态下的 记录 只能查找本系的记录
    public List<Request> getAllApply() {
        UserDetails userDetails=(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long teacher_id=Long.valueOf(userDetails.getUsername());
        //找到老师对应的系号
        int deptId=getDepartmentIdByStudentId(teacher_id);
        //上面表示老师系号
        //找到本系所有申请 select * from pend where
        List<Request> list=requestMapper.selectAllApply();
        List<Request> result=new ArrayList<Request>();
        for (Request request:list){
            if(getDepartmentIdByStudentId(request.getStuId())==deptId){
                //表明此学生的记录是归某老师管的
                result.add(request);
            }else{
                //表明此条记录不归这位老师管.
            }
        }
        return result;
    }


    public int getDepartmentIdByStudentId(Long id){
        return usersMapper.getDepartmentIdByMajorId(usersMapper.getMajorIdByStudentId(id));
    }
}
